package cn.udrm.water.base.v1.manager.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.Table;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import org.hibernate.annotations.GenericGenerator;

/**
 * 系统角色
 * @author liukang
 * @date 2019年3月22日
 */
@Getter
@Setter
@NoArgsConstructor
@Entity(name="BaseRole")
@Table(name="BASE_ORG_ROLE")
@NamedEntityGraphs({
	@NamedEntityGraph(name="BaseRole.all",
			attributeNodes={
			@NamedAttributeNode("organization"),
			@NamedAttributeNode("persons"),
			@NamedAttributeNode("departments"),
			@NamedAttributeNode("resources")
	}),
	@NamedEntityGraph(name="BaseRole.organization",
		attributeNodes={
		@NamedAttributeNode("organization")
	}),
	@NamedEntityGraph(name="BaseRole.persons",
		attributeNodes={
		@NamedAttributeNode("persons")
	}),
	@NamedEntityGraph(name="BaseRole.departments",
		attributeNodes={
		@NamedAttributeNode("departments")
	}),
	@NamedEntityGraph(name="BaseRole.resources",
		attributeNodes={
		@NamedAttributeNode("resources")
	})
})
public class BaseRole implements Serializable {
	
	private static final long serialVersionUID = 1L;

	@Id
	@GenericGenerator(name="idGenerator", strategy="uuid")
	@GeneratedValue(generator="idGenerator")
	@Column(name="ID")
	private String id;
	
	/*
	 * 角色名称
	 */
	private String name;
	private String enName;
	
	@JoinColumn(name="ORGANIZATION_GUID")
	@ManyToOne(optional=true, fetch=FetchType.LAZY)
	private BaseOrganization organization;
	
	/*
	 * 角色-人员多对多
	 */
	@ManyToMany(mappedBy="roles")
	private List<BasePerson> persons;
	/*
	 * 角色-部门多对多
	 */
	@ManyToMany(mappedBy="roles")
	private List<BaseDepartment> departments;
	/*
	 * 角色-资源多对多
	 */
	@ManyToMany(mappedBy="roles")
	private List<BaseResource> resources;
	
	public BaseRole(String id) {
		super();
		this.id = id;
	}
	

}
